package cn.jetpiece.cloud.joss.sdk.config;

import cn.jetpiece.cloud.joss.sdk.core.oss.BucketService;
import cn.jetpiece.cloud.joss.sdk.core.oss.OssService;
import cn.jetpiece.cloud.joss.sdk.core.util.RestUtils;
import cn.jetpiece.cloud.joss.sdk.config.properties.OssApiProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author XuJZ
 * @date 2021/1/19
 */
@Configuration
public class OssApiConfig {

    @Bean
    @ConfigurationProperties(prefix = OssApiProperties.PREFIX)
    public OssApiProperties ossApiProperties() {
        return new OssApiProperties();
    }

    @Bean
    public RestUtils restUtils(OssApiProperties ossApiProperties) {
        RestUtils restUtils = new RestUtils();
        restUtils.setOssApiProperties(ossApiProperties);
        return restUtils;
    }

    @Bean
    public OssService ossService(OssApiProperties ossApiProperties, RestUtils restUtils) {
        OssService ossService = new OssService();
        ossService.setOssApiProperties(ossApiProperties);
        ossService.setRestUtils(restUtils);
        return ossService;
    }

    @Bean
    public BucketService bucketService(RestUtils restUtils) {
        BucketService bucketService = new BucketService();
        bucketService.setRestUtils(restUtils);
        return bucketService;
    }
}
